class DefaultController < ApplicationController
  def index
    @categories = Category.all
    @new_books = Book.find(:all,:limit => 10,:order => 'created_at desc')
    @most_views = Book.find(:all,:limit => 10,:order => 'numviewed desc')
    @most_borrows = Book.find(:all,:limit => 10,:order => 'numborrowed desc')
  end
  def search
    @categories = Category.all
    if(params[:search_type] != nil && params[:search_value] != nil)
      if(params[:search_type].eql? "ID Book")
        type = "Code"
      else
        type = params[:search_type]
      end
      @books = Book.find(:all, :conditions => [type + " LIKE ?", "%" + params[:search_value] + "%"])
    end
    
    @search_type = params[:search_type]
    @search_value = params[:search_value]

    respond_to do |format|
      format.html
    end
  end
end
